﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using MVCWorkflow.Models;

namespace MVCWorkflow.Workflows
{
public sealed class Evaluate : NativeActivity
{
    public InArgument<int> ArticleID { get; set; }
    public OutArgument<string> Operation { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        int articleID = context.GetValue<int>(ArticleID);

        DataContext db = new DataContext();
        Article article = db.Articles.Single(e => e.ArticleID == articleID);
        article.State = "Evaluate";

        db.SaveChanges();

        context.CreateBookmark("Evaluate", new BookmarkCallback(this.Continue));
    }

    protected override bool CanInduceIdle { get { return true; } }

    void Continue(NativeActivityContext context, Bookmark bookmark, object obj)
    {
        Operation.Set(context, obj);
    }
}
}
